<template>
	<view style="padding: 30rpx;">
		<view class="charts-box" v-for="(item, index) in chartDataList" :key="index" style="margin-bottom: 30rpx;">
			<div style="padding: 30rpx;display: flex;align-items: center;justify-content: space-between;">
				<view>{{item.empNane}}</view>
				<view style="color: #999;">优秀次数：{{item.accumulatedNumber}}</view>
			</div>
			<qiun-data-charts :ontouch="true" type="line" :opts="opts" :chartData="item" />
		</view>
		<image src="../../static/images/back-top.png" mode="" class="back-top" @click="backToTop"></image>
	</view>
</template>

<script>
	import {
		QueryAllPersonnelScoreApi,
	} from '@/api/main.js'
	export default {
		data() {
			return {
				chartDataList: [], //所有人员分数
				opts: { //所有人员分数charts 配置
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 10, 0, 15],
					enableScroll: true, //开启图表拖拽功能
					scrollAlign: 'left', //图表滚动条起始位置
					legend: {
						show: false,
					},
					xAxis: {
						disableGrid: true,
						scrollShow: true,
						itemCount: 4,
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						data: [{
							min: 0,
							max: 100
						}]
					},
					extra: {
						line: {
							type: "straight",
							width: 2,
							activeType: "hollow"
						}
					}
				},
				options: null
			};
		},
		onLoad(options) {
			console.log(options)
			this.options = options
			uni.setNavigationBarTitle({
				title: `${options.dept}部门员工分数变化`
			});
		},
		onShow() {
			this.getServerData()
		},
		methods: {
			backToTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			async getServerData() {
				//获取所有人员分数API
				const response = await QueryAllPersonnelScoreApi({
					date: this.options.date,
					dept: this.options.dept,
					'empId': uni.getStorageSync('empid')
				});

				response.data.forEach(item => {
					item.series = [{
						name: "",
						lineType: "dash",
						data: [],
					}]
					item.categories = item.numberOfPeriodList
					item.series[0].name = item.empNane
					item.series[0].data = item.divideList
				});
				this.chartDataList = response.data;
			},
		}
	}
</script>

<style lang="less" scoped>
	.back-top {
		width: 60rpx;
		height: 60rpx;
		position: fixed;
		bottom: 140rpx;
		right: 60rpx;
	}
</style>